var publicApi = require('../../../../script/public.js');
Component({
  options: {
    addGlobalClass: true,
  },
  /**
   * 组件的属性列表
   */
  properties: {
    orderinfo: {
      type: Object,
      value: null
    },
  },
  observers: {
    'orderinfo': function (val) {
      if (val != null) {
        this.setDefaultValue();
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    SolveWayList: [],
    SubmitData: {
      SOLVEWAY: '',
      SOLVEREMARK: ''
    }
  },
  lifetimes: {
    attached() {
      this.getList();
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getList() {
      publicApi.GetPCodeList({
        CODE_TYPE: 'SolveWay',
      }).then(res => {
        if (res.code === 200) {
          const resData = res.data || [];
          const list = resData.find(item => item.VALUE === '010');
          if (list) {
            const children = [...list.Childrens];
            children.push({NAME: '其他',VALUE: '099'});
            this.setData({
              SolveWayList: children,
              // "SubmitData.SOLVEWAY": children[0].VALUE
            });
          }
        }
      });
    },
    SolveWayRadioChange(e) {
      this.setData({
        "SubmitData.SOLVEWAY": e.detail.value
      });
    },
    SolveRemarkChange: function (e) {
      this.setData({
        "SubmitData.SOLVEREMARK": e.detail.value
      });
    },
    setDefaultValue() {
      this.setData({
        "SubmitData.SOLVEWAY": this.data.orderinfo.SolveWay,
        "SubmitData.SOLVEREMARK": this.data.orderinfo.SolveRemark,
      });
    },
    getSubmitData(isCheck = true) {
      if(isCheck){
        if (this.data.SubmitData.SOLVEWAY == null || this.data.SubmitData.SOLVEWAY == '') {
          wx.showToast({
            title: '解决措施不能为空！',
            icon: 'none',
            duration: 2000
          });
          return null;
        }else{
          if(this.data.SubmitData.SOLVEWAY === '099'){
            if(this.data.SubmitData.SOLVEREMARK == null || this.data.SubmitData.SOLVEREMARK == ''){
              wx.showToast({
                title: '其他措施文字说明不能为空！',
                icon: 'none',
                duration: 2000
              });
              return null;
            }
          }
        }
      }
      const submitData = {
        ProcHandReason: '',
        OTHERREASON: '',
        SOLVEWAY: this.data.SubmitData.SOLVEWAY,
        SOLVEREMARK: this.data.SubmitData.SOLVEREMARK,
      }
      return submitData;
    },
  }
})